/* creates a new server socket node and adds it to the socket set.
returns socket id on success. -1 on failure.
socket_type is one of INET or UNIX */
-int socket_open_tcp_server(socket_manager*, int port, char* listen_ip );
+int socket_open_tcp_server(socket_manager*, int port, const char* listen_ip );
int socket_open_unix_server(socket_manager* mgr, char* path);
-int socket_open_udp_server( socket_manager* mgr, int port, char* listen_ip );
+int socket_open_udp_server( socket_manager* mgr, int port, const char* listen_ip );
/* creates a client TCP socket and adds it to the socket set.
returns 0 on success. -1 on failure. */
-int socket_open_tcp_client(socket_manager*, int port, char* dest_addr);
+int socket_open_tcp_client(socket_manager*, int port, const char* dest_addr);
/* creates a client UNIX socket and adds it to the socket set.
returns 0 on success. -1 on failure. */
-int socket_open_unix_client(socket_manager*, char* sock_path);
+int socket_open_unix_client(socket_manager*, const char* sock_path);
int socket_open_udp_client( socket_manager* mgr, int port, char* dest_addr);
/* creates a new server socket node and adds it to the socket set.
returns new socket fd on success. -1 on failure.
socket_type is one of INET or UNIX */
-int socket_open_tcp_server(socket_manager* mgr, int port, char* listen_ip) {
+int socket_open_tcp_server(socket_manager* mgr, int port, const char* listen_ip) {
if( mgr == NULL ) {
osrfLogWarning( OSRF_LOG_MARK, "socket_open_tcp_server(): NULL mgr");
server_addr.sin_family = AF_INET;
if(listen_ip != NULL) {
- server_addr.sin_addr.s_addr = inet_addr(listen_ip);
+ struct in_addr addr;
+ if( inet_aton( listen_ip, &addr ) )
+ server_addr.sin_addr.s_addr = addr.s_addr;
+ else {
+ osrfLogError( OSRF_LOG_MARK, "Listener address is invalid: %s", listen_ip );
+ return -1;
+ }
} else {
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
}
int socket_open_udp_server(
- socket_manager* mgr, int port, char* listen_ip ) {
+ socket_manager* mgr, int port, const char* listen_ip ) {
int sockfd;
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
- if(listen_ip) server_addr.sin_addr.s_addr = inet_addr(listen_ip);
- else server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ if(listen_ip) {
+ struct in_addr addr;
+ if( inet_aton( listen_ip, &addr ) )
+ server_addr.sin_addr.s_addr = addr.s_addr;
+ else {
+ osrfLogError( OSRF_LOG_MARK, "UDP listener address is invalid: %s", listen_ip );
+ return -1;
+ }
+ } else server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
errno = 0;
if( (bind (sockfd, (struct sockaddr *) &server_addr,sizeof(server_addr))) ) {
}
-int socket_open_tcp_client(socket_manager* mgr, int port, char* dest_addr) {
+int socket_open_tcp_client(socket_manager* mgr, int port, const char* dest_addr) {
struct sockaddr_in remoteAddr, localAddr;
struct hostent *hptr;