X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/85ce9d3ecb3e6888dae590b3a8e347e0a2131bd9..c7bceafda9c7c1045b398d8454a0a2ed0fbd9170:/gameserv/sockhelp.cpp?ds=sidebyside diff --git a/gameserv/sockhelp.cpp b/gameserv/sockhelp.cpp index c68dd8e..a5af1e3 100644 --- a/gameserv/sockhelp.cpp +++ b/gameserv/sockhelp.cpp @@ -13,6 +13,7 @@ */ #include "sockhelp.h" +#include "extern.h" /* Take a service name, and a service type, and return a port number. If the @@ -22,19 +23,14 @@ int atoport(char *service, char *proto) { int port; long int lport; - struct servent *serv; char *errpos; - /* First try to read it from /etc/services */ - serv = getservbyname(service, proto); - if (serv != NULL) - port = serv->s_port; - else { /* Not in services, maybe a number? */ lport = strtol(service,&errpos,0); if ( (errpos[0] != 0) || (lport < 1) || (lport > 65535) ) return -1; /* Invalid port address */ + port = htons(lport); - } + return port; } @@ -43,13 +39,7 @@ int atoport(char *service, char *proto) struct in_addr *atoaddr(char *address) { struct hostent *host; - static struct in_addr saddr; - /* First try it as aaa.bbb.ccc.ddd. */ - saddr.s_addr = inet_addr(address); - if (saddr.s_addr != -1) { - return &saddr; - } host = gethostbyname(address); if (host != NULL) { return (struct in_addr *) *host->h_addr_list; @@ -191,7 +181,7 @@ int make_connection(char *service, int type, char *netaddress) sock = socket(AF_INET, type, 0); - printf("Connecting to %s on port %d.\n",inet_ntoa(*addr),htons(port)); + log("Connecting to %s on port %d.",inet_ntoa(*addr),htons(port)); if (type == SOCK_STREAM) { connected = connect(sock, (struct sockaddr *) &address, @@ -242,7 +232,7 @@ int sock_read(int sockfd, char *buf, size_t count) int sock_gets(int sockfd, char *str, size_t count) { int bytes_read; - int total_count = 0; + unsigned int total_count = 0; char *current_position; char last_read = 0;