diff options
author | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-03-02 00:26:11 +0800 |
---|---|---|
committer | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-03-02 00:26:11 +0800 |
commit | 11cf3f25d98f02e3e02984b5e372159d9b6c555b (patch) | |
tree | a39555c4a537b8badff597bbfde9c4ee68558ef5 | |
parent | d2b177e6004b566092ba398664e3a71b8a405971 (diff) | |
download | pttbbs-11cf3f25d98f02e3e02984b5e372159d9b6c555b.tar pttbbs-11cf3f25d98f02e3e02984b5e372159d9b6c555b.tar.gz pttbbs-11cf3f25d98f02e3e02984b5e372159d9b6c555b.tar.bz2 pttbbs-11cf3f25d98f02e3e02984b5e372159d9b6c555b.tar.lz pttbbs-11cf3f25d98f02e3e02984b5e372159d9b6c555b.tar.xz pttbbs-11cf3f25d98f02e3e02984b5e372159d9b6c555b.tar.zst pttbbs-11cf3f25d98f02e3e02984b5e372159d9b6c555b.zip |
able to choose ip to bind
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2568 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | cacheserver/utmpserver.c | 12 | ||||
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | mbbsd/stuff.c | 7 |
3 files changed, 14 insertions, 7 deletions
diff --git a/cacheserver/utmpserver.c b/cacheserver/utmpserver.c index 82832b8f..94c6c0f1 100644 --- a/cacheserver/utmpserver.c +++ b/cacheserver/utmpserver.c @@ -73,20 +73,24 @@ int main(int argc, char **argv) { struct sockaddr_in clientaddr; int ch, port = 5120, sfd, cfd, len, index, i, uid; + char iface_ip[16] = {NULL}; - while( (ch = getopt(argc, argv, "p:h")) != -1 ) + while( (ch = getopt(argc, argv, "p:i:h")) != -1 ) switch( ch ){ case 'p': port = atoi(optarg); break; - + case 'i': + host = strncpy(iface_ip, optarg, 16); + host[15] = 0; + break; case 'h': default: - fprintf(stderr, "usage: utmpserver [-p port]\n"); + fprintf(stderr, "usage: utmpserver [-i interface_ip] [-p port]\n"); return 1; } - if( (sfd = tobind(port)) < 0 ) + if( (sfd = tobind(iface_ip, port)) < 0 ) return 1; while( 1 ){ diff --git a/include/proto.h b/include/proto.h index a6b9104d..771151c5 100644 --- a/include/proto.h +++ b/include/proto.h @@ -595,7 +595,7 @@ int qsort_intcompar(const void *a, const void *b); void FREE(void *ptr); #endif #ifdef OUTTACACHE -int tobind(int port); +int tobind(char *iface_ip, int port); int toconnect(char *host, int port); int toread(int fd, void *buf, int len); int towrite(int fd, void *buf, int len); diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 3e44efdf..ba3253bf 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -955,7 +955,7 @@ time4_t time4(time4_t *ptr) #endif #ifdef OUTTACACHE -int tobind(int port) +int tobind(char * host, int port) { int sockfd, val; struct sockaddr_in servaddr; @@ -968,7 +968,10 @@ int tobind(int port) (char *)&val, sizeof(val)); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + if (!host || host[0] == NULL) + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + else if (inet_aton(host, &servaddr.sin_addr) == 0) + err(1, NULL); servaddr.sin_port = htons(port); if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) { perror("bind()"); |