This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dennis Richie would turn over in his grave.
- Loading branch information
1 parent
debf552
commit cd23e6d
Showing
10 changed files
with
161 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CFLAGS =-Wall -Wextra | ||
|
||
BUILDTYPE ?= Release | ||
|
||
ifeq ($(BUILDTYPE),Release) | ||
CFLAGS += -O3 | ||
else | ||
CFLAGS += -O0 -g | ||
endif | ||
|
||
.PHONY: all clean | ||
|
||
all: openshift.o | ||
|
||
clean: | ||
@rm -f *.o *.a | ||
|
||
openshift.o: openshift.c | ||
$(CC) $(CFLAGS) -o openshift.o -c openshift.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
#include <arpa/inet.h> | ||
#include <pthread.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "openshift.h" | ||
|
||
|
||
/* Init to defaults; override only if OPENSHIFT_INTERNAL_IP is set; */ | ||
static const char* openshift_loopback_name_ = "127.0.0.1"; | ||
static uint32_t openshift_loopback_addr_ = (uint32_t) 0x7f000001; | ||
|
||
static pthread_once_t openshift_loopback_addr_init_guard_ = PTHREAD_ONCE_INIT; | ||
|
||
|
||
static void openshift_loopback_addr_init(void) { | ||
const char* name; | ||
const uint32_t addr; | ||
|
||
name = getenv("OPENSHIFT_INTERNAL_IP"); | ||
if (name == NULL) { | ||
/* Env var not found - stick to 127.0.0.1. */ | ||
return; | ||
} | ||
|
||
if (!inet_pton(AF_INET, name, (void*) &addr)) { | ||
/* Env var was not a valid IP - stick to 127.0.0.1. */ | ||
return; | ||
} | ||
|
||
/* Convert to machine byte order. */ | ||
openshift_loopback_addr_ = ntohl(addr); | ||
|
||
openshift_loopback_name_ = strdup(name); | ||
if (openshift_loopback_name_ == NULL) { | ||
/* Out of memory */ | ||
abort(); | ||
} | ||
} | ||
|
||
|
||
uint32_t openshift_loopback_addr(void) { | ||
pthread_once(&openshift_loopback_addr_init_guard_, | ||
openshift_loopback_addr_init); | ||
|
||
return openshift_loopback_addr_; | ||
} | ||
|
||
const char* openshift_loopback_name(void) { | ||
pthread_once(&openshift_loopback_addr_init_guard_, | ||
openshift_loopback_addr_init); | ||
|
||
return openshift_loopback_name_; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
#ifndef OPENSHIFT_H_ | ||
#define OPENSHIFT_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <arpa/inet.h> | ||
#include <stdint.h> | ||
|
||
|
||
uint32_t openshift_loopback_addr(void); | ||
const char* openshift_loopback_name(void); | ||
|
||
|
||
/* Redefine INADDR_LOOPBACK to use the openshift loopback address. */ | ||
#undef INADDR_LOOPBACK | ||
#define INADDR_LOOPBACK (openshift_loopback_addr()) | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters