Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Where's socklen_t?!

Where's socklen_t?!
Thread Tools
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
May 5, 2003, 01:01 AM
 
Hi,
Does anyone know what header file this struct lives in? I'm trying to compile my friends networking code and it can't find this. Any ideas? It compiles fine on Debian Linux boxes. Here's the whole file:

Code:
#include <sys/types.h> /* basic system data types */ #include <sys/socket.h> /* basic socket definitions */ #include <sys/time.h> /* timeval{} for select() */ #include <time.h> /* timespec{} for pselect() */ #include <netinet/in.h> /* sockaddr_in{} and other Internet defns */ #include <arpa/inet.h> /* inet(3) functions */ #include <errno.h> #include <fcntl.h> /* for nonblocking */ #include <netdb.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> /* for S_xxx file mode constants */ #include <sys/uio.h> /* for iovec{} and readv/writev */ #include <unistd.h> #include <sys/wait.h> #include <sys/un.h> /* for Unix domain sockets */ #include <iostream> using namespace std; /* Define some port number that can be used for client-servers */ #define SERV_PORT 9877 /* TCP and UDP client-servers> */ //This is just used for convenience #define SA struct sockaddr //MAX NUMBER OF CHARACTERS FOR BUFFERS #define MAXLINE 4096 /* Following could be derived from SOMAXCONN in <sys/socket.h>, but many * kernels still #define it as 5, while actually supporting many more */ #define LISTENQ 1024 /* 2nd argument to listen() */ void str_cli(FILE *, int); void str_echo(int); ssize_t Readline(int, char *, int); ssize_t readline(int, char *, int); ssize_t my_read(int, char *); void Writen(int, const char *, ssize_t); ssize_t writen(int, const char *, size_t); char* Sock_ntop(const SA *, socklen_t); int Socket(int, int, int); char *Fgets(char *, int, FILE *); void Fputs(const char *, FILE *); char *sock_ntop(const SA *, socklen_t); int Accept(int, SA *, socklen_t *); void Bind(int, const SA *, socklen_t); void Listen(int, int); void Close(int); int Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);

On the line that says
Code:
char* Sock_ntop(const SA *, socklen_t);
I get this error: "type specifier omitted for parameter 'socklen_t'. I'm assuming it's just 'cause it can't find what socklen_t is, so it gets confused. It only dies on the ones with socklen_t in them. Any help? thanks!

gabe
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
May 5, 2003, 05:33 AM
 
Just define it as an unsigned int and move on.

Looks like that's what apache, php, and python do.
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 5, 2003, 01:38 PM
 
You can also use Sock_ntoa()
I be that insane n***a from the psycho ward.
     
Zimwy  (op)
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
May 5, 2003, 01:52 PM
 
Originally posted by type_r503:
You can also use Sock_ntoa()
Well, it's not the method call that gives the problem, right? I declared socklen_t as an unsigned int, and then later on in the code, it said "Invalid conversion from socklen_t to int*"

Grr. Any ideas now?

gabe
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 5, 2003, 03:09 PM
 
You need to use '&' before the variable to pass a reference to the pointer.
I be that insane n***a from the psycho ward.
     
Zimwy  (op)
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
May 5, 2003, 07:48 PM
 
Sorry, I gave the wrong error message. Let me sum up:

I added this:
Code:
typedef u_int32_t socklen_t;
to the header file. So, that let's it compile, but then it dies later on at things like this:

Code:
int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr) { int n; again: if ( (n = accept(fd, sa, salenptr)) < 0) { #ifdef EPROTO if (errno == EPROTO || errno == ECONNABORTED) #else if (errno == ECONNABORTED) #endif goto again; else cout<<"accept error"; } return(n); }
It says "networkSupport.C:86: warning: invalid conversion from `socklen_t*' to `int*'" on this line:
Code:
if ( (n = accept(fd, sa, salenptr)) < 0) {
I also get this error:
Code:
networkSupport.C:26: no matching function for call to `max(short int&, int&)'
In this method:
Code:
void str_cli(FILE *fp, int sockfd) { char sendline[MAXLINE]; char recvline[MAXLINE]; int endClient=0; int maxfdp1; fd_set rset; struct timeval tv; //If select finds nothing ready, set wait time to 0 tv.tv_sec = 0; tv.tv_usec = 0; while (!endClient) { cout<<"Enter message to send to server: "; if(Fgets(sendline, MAXLINE, fp) ==NULL) endClient=1; Writen(sockfd, sendline, strlen(sendline)); FD_SET(sockfd, &rset); maxfdp1 = max(fileno(fp), sockfd) + 1; Select(maxfdp1, &rset, NULL, NULL, (timeval* ) &tv); //Check if there's anything to read on the socket if(FD_ISSET(sockfd, &rset)) { //Read from the socket to recvline if (Readline(sockfd, recvline, MAXLINE) == 0){ cout<<"str_cli: server terminated prematurely"; endClient=1; } //Print the message cout<<"Message from the server: "; fputs(recvline, stdout); } else { cout<<"Nothing to read on the socket"; } } }
on this line:
Code:
maxfdp1 = max(fileno(fp), sockfd) + 1;
any ideas?
     
Grizzled Veteran
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 8, 2003, 12:02 AM
 
Read what it's telling you:

Code:
warning: invalid conversion from `socklen_t*' to `int*'" on this line: if ( (n = accept(fd, sa, salenptr)) < 0) {
What does that tell you?

That you're trying to convert a socklen_t pointer (your salenptr parameter) to an int * in the third parameter of accept. Why? Because accept wants an int * (see man 2 accept).

I suspect that if you change your typedef to a plain int, it will work.

I believe in OS X 10.1.5 and earlier, the correct typedef would be an int, since FreeBSD 3.x and earlier used an int. In OS X 10.2 and later, the correct typedef *should* be an unsigned int.

What version of OS X are you using?


Code:
networkSupport.C:26: no matching function for call to `max(short int&, int&)'
Here again, it's telling you that the types you're passing are not what it expects.

Wade
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:29 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2