Ask a Question related to UNIX Programming, Design and Development.
-
Barry Margolin #1
Re: Socket Setup and program in C- help
In article <5d7d3bea.0307110528.24e72923@posting.google.com >,
thumor <ttejas@yahoo.com> wrote:....> if ( bind(server_fd,(struct sockaddr
>*)&remote_addr,sizeof(struct sockaddr_in)) == -1)When you call bind(), you're specifying the *local* address and port that>I am getting error number 227 : EADDRNOTAVAIL on bind, when I call
>function
>OpenPort("MYPORTNAME") in my main().
>
the server should listen on. You're getting EADDRNOTAVAIL because the
address in remote_addr is a remote address, not one of the server's local
addresses.
Connect() is for a client connecting to a server.>If I replace the bind/accept/listen with a connect as follows; I get
>error
>number 238 (ETIMEDOUT).
If you're trying to configure it so that *only* this one address can
connect to the server, I don't think sockets provides any way to do that.
What you need to do is have your server call getpeername() when a
connection comes in. If the remote address isn't the allowed client, it
should then close the connection.
--
Barry Margolin, [email]barry.margolin@level3.com[/email]
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Barry Margolin Guest
-
best setup for school laptop program
Hi, all. I'm posting here because I know the regulars in this ng are Sysadmin Gods (more flattery available Upon Request). We've got a small school... -
PDF and program won't open; "Error in Acrord32" "This program has performed an illegal operation and
I recently had a browser hijacker. Fixed it with Norton and Lavasoft. Now, after downloading new Reader 6.0, I can't open anything. Only gives... -
Page setup/paper setup
Hi I use Freehand MXa in MacOSX 13.2. I wonder, does Freehands own paper setup (in print dialog box) owerride all paper setup settings.(In... -
Socket.accept problem via Socket.for_fd($stdin.fileno)
Hi, I am experiencing a rather infuriating problem with Socket.accept on Windows XP. The problem exists when I try to create a Socket from... -
Distinguishing between socket buffer full & socket disconnected
I am using the IO::Select method can_write() to flow control the writing of a large amount of data to a socket, where the writer may well run ahead... -
thumor #2
Re: Socket Setup and program in C- help
Barry Margolin <barry.margolin@level3.com> wrote in message news:<eXzPa.20$0z4.4@news.level3.com>...
That was great help. I used following to correct that:> In article <5d7d3bea.0307110528.24e72923@posting.google.com >,
> thumor <ttejas@yahoo.com> wrote:> ...> > if ( bind(server_fd,(struct sockaddr
> >*)&remote_addr,sizeof(struct sockaddr_in)) == -1)>> >I am getting error number 227 : EADDRNOTAVAIL on bind, when I call
> >function
> >OpenPort("MYPORTNAME") in my main().
> >
> When you call bind(), you're specifying the *local* address and port that
> the server should listen on. You're getting EADDRNOTAVAIL because the
> address in remote_addr is a remote address, not one of the server's local
> addresses.
>
/* Veriables defined */
struct sockaddr_in local_addr;
int addrlen;
/* Initialize variables */
memset( (char *)&local_addr, 0, sizeof(struct sockaddr_in));
/* Placed this before bind */
if ( getsockaddr(server_fd, &local_addr, &addrlen) == -1)
{
Log_message("Error (%d) on getsockaddr",errno);
}
else
{
Log_message("Got local address");
}
/* Changed bind as above to use &local_addr */
-- That worked for bind. listen() went fine (no errors).
Then it seems I never get past accept().
Do I use local_addr or remote_addr for accept() ?
Seems like nothing happens after listen().
>> >If I replace the bind/accept/listen with a connect as follows; I get
> >error
> >number 238 (ETIMEDOUT).
> Connect() is for a client connecting to a server.
>
> If you're trying to configure it so that *only* this one address can
> connect to the server, I don't think sockets provides any way to do that.
> What you need to do is have your server call getpeername() when a
> connection comes in. If the remote address isn't the allowed client, it
> should then close the connection.thumor Guest
-
Barry Margolin #3
Re: Socket Setup and program in C- help
In article <5d7d3bea.0307140757.43c3b92b@posting.google.com >,
thumor <ttejas@yahoo.com> wrote:Why are you doing this? Calling bind() is what sets the socket's local>Barry Margolin <barry.margolin@level3.com> wrote in message
>news:<eXzPa.20$0z4.4@news.level3.com>...>>> In article <5d7d3bea.0307110528.24e72923@posting.google.com >,
>> thumor <ttejas@yahoo.com> wrote:>> ...>> > if ( bind(server_fd,(struct sockaddr
>> >*)&remote_addr,sizeof(struct sockaddr_in)) == -1)>>>> >I am getting error number 227 : EADDRNOTAVAIL on bind, when I call
>> >function
>> >OpenPort("MYPORTNAME") in my main().
>> >
>> When you call bind(), you're specifying the *local* address and port that
>> the server should listen on. You're getting EADDRNOTAVAIL because the
>> address in remote_addr is a remote address, not one of the server's local
>> addresses.
>>
>That was great help. I used following to correct that:
>
>/* Veriables defined */
>
>struct sockaddr_in local_addr;
>int addrlen;
>
>/* Initialize variables */
>memset( (char *)&local_addr, 0, sizeof(struct sockaddr_in));
>
>/* Placed this before bind */
>
>if ( getsockaddr(server_fd, &local_addr, &addrlen) == -1)
>{
> Log_message("Error (%d) on getsockaddr",errno);
>}
>else
>{
> Log_message("Got local address");
>}
address. What's the purpose of calling getsockaddr before that?
I'm not sure what got put into local_addr by the above call.>/* Changed bind as above to use &local_addr */
Where did you put that call in relation to the code that fills in the port
number?
Accept() fills in a structure with the client's address.>-- That worked for bind. listen() went fine (no errors).
>
>Then it seems I never get past accept().
>Do I use local_addr or remote_addr for accept() ?
I think you need to get a copy of "Unix Network Programming, Vol.1".
--
Barry Margolin, [email]barry.margolin@level3.com[/email]
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Barry Margolin Guest
-
thumor #4
Re: Socket Setup and program in C- help
Barry Margolin <barry.margolin@level3.com> wrote in message news:<pJDQa.148$0z4.88@news.level3.com>...
Whether I use getsockaddr() or not, the bottom line is the same,> In article <5d7d3bea.0307140757.43c3b92b@posting.google.com >,
> thumor <ttejas@yahoo.com> wrote:> ...> >Barry Margolin <barry.margolin@level3.com> wrote in message
> >news:<eXzPa.20$0z4.4@news.level3.com>...> >> In article <5d7d3bea.0307110528.24e72923@posting.google.com >,
> >> thumor <ttejas@yahoo.com> wrote:
> >> > if ( bind(server_fd,(struct sockaddr
> >> >*)&remote_addr,sizeof(struct sockaddr_in)) == -1)>> >> >> >I am getting error number 227 : EADDRNOTAVAIL on bind, when I call
> >> >function
> >> >OpenPort("MYPORTNAME") in my main().
> >> >
> >>
> >> When you call bind(), you're specifying the *local* address and port that
> >> the server should listen on. You're getting EADDRNOTAVAIL because the
> >> address in remote_addr is a remote address, not one of the server's local
> >> addresses.
> >>
> >That was great help. I used following to correct that:
> >
> >/* Veriables defined */
> >
> >struct sockaddr_in local_addr;
> >int addrlen;
> >
> >/* Initialize variables */
> >memset( (char *)&local_addr, 0, sizeof(struct sockaddr_in));
> >
> >/* Placed this before bind */
> >
> >if ( getsockaddr(server_fd, &local_addr, &addrlen) == -1)
> >{
> > Log_message("Error (%d) on getsockaddr",errno);
> >}
> >else
> >{
> > Log_message("Got local address");
> >}
> Why are you doing this? Calling bind() is what sets the socket's local
> address. What's the purpose of calling getsockaddr before that?
>>> >/* Changed bind as above to use &local_addr */
> I'm not sure what got put into local_addr by the above call.
>
> Where did you put that call in relation to the code that fills in the port
> number?
>>> >-- That worked for bind. listen() went fine (no errors).
> >
> >Then it seems I never get past accept().
> >Do I use local_addr or remote_addr for accept() ?
> Accept() fills in a structure with the client's address.
>
> I think you need to get a copy of "Unix Network Programming, Vol.1".
my accept() never returns (using local_addr).
Is it that the accept() will come back ONLY when the client-side issues a
*connect* on the port; giving me the *new* socket address (nportFD) to
work with?
thumor Guest
-
Barry Margolin #5
Re: Socket Setup and program in C- help
In article <5d7d3bea.0307160551.9d886fc@posting.google.com> ,
thumor <ttejas@yahoo.com> wrote:Yes. The purpose of accept() is to wait for a connection, and when it>Is it that the accept() will come back ONLY when the client-side issues a
>*connect* on the port; giving me the *new* socket address (nportFD) to
>work with?
comes in it returns the FD for that new connection to the server.
--
Barry Margolin, [email]barry.margolin@level3.com[/email]
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Barry Margolin Guest



Reply With Quote

