From: John Gordon on
In <4bf1a10c$0$26945$bbae4d71(a)news.suddenlink.net> "Bill Cunningham" <nospam(a)nspam.invalid> writes:

> Why do I keep getting a segmentation fault here? I want to write to an
> echo server and receive back.

Tell us what line of code generates the seg fault.
Tell us what's in the mysterious header file main.h.

--
John Gordon A is for Amy, who fell down the stairs
gordon(a)panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

From: Ian Collins on
On 05/18/10 09:32 AM, Bill Cunningham wrote:
> "David Schwartz"<davids(a)webmaster.com> wrote in message
> news:cfe79619-dc92-4339-9614-b5aa0d58a434(a)v12g2000prb.googlegroups.com...
>
> You need to generate and analyze a core dump to make sense of the
> segmentation fault. Or at least add printf's or similar commands so
> you can figure out which line is faulting.
>
> I don't know how to do that. I'm not getting a core dump. Should I
> generate one somehow? I do have gdb. So then the source code looks fine
> there's just something happening somewhere?
>
> I don't know what a segmentation fault means though I've seen many of
> them.

Oh come on Bill, in you decade or so of trolling Usenet, you must had
more than your fair share and worked out what they are.

--
Ian Collins
From: John Gordon on
In <4bf1b5cc$0$12426$bbae4d71(a)news.suddenlink.net> "Bill Cunningham" <nospam(a)nspam.invalid> writes:

> I don't know how to do that. I'm not getting a core dump. Should I

Is the program setuid, or are you running it in a directory where you
don't have write permission?

> I don't know what a segmentation fault means though I've seen many of
> them.

Usually it means the program tried to write to a memory location that it
doesn't own, which is in turn usually caused by a null or overwritten
pointer.

--
John Gordon A is for Amy, who fell down the stairs
gordon(a)panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

From: Lew Pitcher on
On May 17, 2010 16:03, in comp.unix.programmer, nospam(a)nspam.invalid wrote:

> Why do I keep getting a segmentation fault here? I want to write to an
> echo server and receive back.
>
> #include "main.h"
>
> struct addrinfo ad, *p;
>
> int client(char *ip, char *port)
> {
> int rv, c, sock;
> char *buf = "hello\n";
> memset(&ad, 0, sizeof ad);
> getaddrinfo(ip, port, &ad, &p);

Bill...

What is p pointing at?


> ad.ai_family = AF_INET;
> ad.ai_socktype = SOCK_STREAM;
> if ((sock = socket(p->ai_family, p->ai_socktype, 0)) == -1)
> return -1;
> if ((c = connect(sock, p->ai_addr, p->ai_addrlen)) == -1)
> return -2;
> fcntl(sock, F_SETFL, O_NONBLOCK);
> if ((rv = write(sock, buf, sizeof buf)) == -1)
> return -3;
> return 0;
> }
>
> int main()
> {
> int r;
> r = client(NULL, "4");
> printf("%d\n", r);
> }
>
>
>

--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------


From: Lew Pitcher on
On May 17, 2010 18:05, in comp.unix.programmer, lpitcher(a)teksavvy.com wrote:

> On May 17, 2010 16:03, in comp.unix.programmer, nospam(a)nspam.invalid
> wrote:
>
>> Why do I keep getting a segmentation fault here? I want to write to
>> an
>> echo server and receive back.
>>
>> #include "main.h"
>>
>> struct addrinfo ad, *p;
>>
>> int client(char *ip, char *port)
>> {
>> int rv, c, sock;
>> char *buf = "hello\n";
>> memset(&ad, 0, sizeof ad);
>> getaddrinfo(ip, port, &ad, &p);
>
> Bill...
>
> What is p pointing at?

Never mind. I found it.

Thanks

>
>> ad.ai_family = AF_INET;
>> ad.ai_socktype = SOCK_STREAM;
>> if ((sock = socket(p->ai_family, p->ai_socktype, 0)) == -1)
>> return -1;
>> if ((c = connect(sock, p->ai_addr, p->ai_addrlen)) == -1)
>> return -2;
>> fcntl(sock, F_SETFL, O_NONBLOCK);
>> if ((rv = write(sock, buf, sizeof buf)) == -1)
>> return -3;
>> return 0;
>> }
>>
>> int main()
>> {
>> int r;
>> r = client(NULL, "4");
>> printf("%d\n", r);
>> }
>>
>>
>>
>

--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------