puts("Usage:");
puts(" -p <port> | --port <port>");
puts(" --config=<config_file>");
+ puts(" --disable-peer-addr-print");
}
Args parse_args(int argc, char **argv) {
++argv;
} else if (strncmp(argv[0], "--config=", 9) == 0 && strlen(argv[0]) > 9) {
args.config_file = argv[0] + 9;
+ } else if (strcmp(argv[0], "--disable-peer-addr-print") == 0) {
+ args.flags |= 1;
} else {
puts("ERROR: Invalid args!\n");
print_usage();
#define SEODISPARATE_COM_C_SIMPLE_HTTP_ARG_PARSE_H_
typedef struct Args {
+ // xxxx xxx0 - enable peer addr print.
+ // xxxx xxx1 - disable peer addr print.
unsigned short flags;
unsigned short port;
// Does not need to be free'd, this should point to a string in argv.
}
int main(int argc, char **argv) {
- Args args = parse_args(argc, argv);
+ const Args args = parse_args(argc, argv);
if (!args.config_file) {
fprintf(stderr, "ERROR Config file not specified!\n");
printf("WARNING: accept: errno %d\n", errno);
} else if (ret >= 0) {
// Received connection, handle it.
- printf("Peer connected: addr is ");
- for (unsigned int idx = 0; idx < 16; ++idx) {
- if (idx % 2 == 0 && idx > 0) {
- printf(":");
+ if ((args.flags & 1) == 0) {
+ printf("Peer connected: addr is ");
+ for (unsigned int idx = 0; idx < 16; ++idx) {
+ if (idx % 2 == 0 && idx > 0) {
+ printf(":");
+ }
+ printf("%02x", peer_info.sin6_addr.s6_addr[idx]);
}
- printf("%02x", peer_info.sin6_addr.s6_addr[idx]);
+ puts("");
+ } else {
+ printf("Peer connected.\n");
}
- puts("");
int connection_fd = ret;
read_ret = read(connection_fd, recv_buf, C_SIMPLE_HTTP_RECV_BUF_SIZE);
if (read_ret < 0) {