Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #13311 > unrolled thread
| Started by | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| First post | 2015-01-05 21:30 -0500 |
| Last post | 2015-01-06 18:44 -0500 |
| Articles | 13 — 5 participants |
Back to article view | Back to comp.os.linux.misc
pcap problem "Bill Cunningham" <nospam@nspam.invalid> - 2015-01-05 21:30 -0500
Re: pcap problem John McCue <jmccue@jmclin0.bstnma.east.verizon.net> - 2015-01-06 18:09 +0000
Re: pcap problem "Bill Cunningham" <nospam@nspam.invalid> - 2015-01-06 14:54 -0500
Re: pcap problem Rich <rich@example.invalid> - 2015-01-06 20:05 +0000
Re: pcap problem Richard Kettlewell <rjk@greenend.org.uk> - 2015-01-06 20:11 +0000
Re: pcap problem Rich <rich@example.invalid> - 2015-01-06 21:22 +0000
Re: pcap problem "Bill Cunningham" <nospam@nspam.invalid> - 2015-01-06 18:08 -0500
Re: pcap problem Richard Kettlewell <rjk@greenend.org.uk> - 2015-01-07 09:20 +0000
Re: pcap problem Mark Blair <mblair@quantumdata.com> - 2015-01-06 14:14 -0600
Re: pcap problem "Bill Cunningham" <nospam@nspam.invalid> - 2015-01-06 18:05 -0500
Re: pcap problem "Bill Cunningham" <nospam@nspam.invalid> - 2015-01-06 18:12 -0500
Re: pcap problem Rich <rich@example.invalid> - 2015-01-06 23:37 +0000
Re: pcap problem "Bill Cunningham" <nospam@nspam.invalid> - 2015-01-06 18:44 -0500
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2015-01-05 21:30 -0500 |
| Subject | pcap problem |
| Message-ID | <m8fhc1$d5g$1@speranza.aioe.org> |
This is the code I have so far and I run into a segmentation fault. The
debugger says it has something to do with "activate".
#include <stdio.h>
#include <pcap/pcap.h>
#include <stdlib.h>
int main()
{
pcap_t *pp;
char *perr;
int stat;
int datalink;
char errbuf[PCAP_ERRBUF_SIZE];
pp = pcap_create("handle", errbuf);
if (pp = NULL) {
fputs(errbuf, stderr);
exit(1);
}
stat = pcap_activate(pp);
if (stat != 0) {
perr = pcap_geterr(pp);
printf("%s\n", perr);
exit(1);
}
datalink = pcap_datalink(pp);
if (datalink = PCAP_ERROR_NOT_ACTIVATED) {
fputs("not activated error\n", stderr);
exit(1);
}
puts("fine");
return 0;
}
Bill
[toc] | [next] | [standalone]
| From | John McCue <jmccue@jmclin0.bstnma.east.verizon.net> |
|---|---|
| Date | 2015-01-06 18:09 +0000 |
| Message-ID | <m8h8cv$7m3$1@dont-email.me> |
| In reply to | #13311 |
Bill Cunningham <nospam@nspam.invalid> wrote: > This is the code I have so far and I run into a segmentation fault. The > debugger says it has something to do with "activate". Check your if statements :) Not sure if that is your issue but best to validate the if statements, esp the equal ones. <snip> John
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2015-01-06 14:54 -0500 |
| Message-ID | <m8hehg$p26$1@speranza.aioe.org> |
| In reply to | #13319 |
"John McCue" <jmccue@jmclin0.bstnma.east.verizon.net> wrote in
> Check your if statements :)
> Not sure if that is your issue but best to validate the
> if statements, esp the equal ones.
The thing is I know nothing hardly about this API. Am I even using the
functions as they should be used. Where pointers are asked for should I be
passing them and not what is being pointed too? What do you mean validate
IFs ?
Bill
[toc] | [prev] | [next] | [standalone]
| From | Rich <rich@example.invalid> |
|---|---|
| Date | 2015-01-06 20:05 +0000 |
| Message-ID | <m8hf6c$7t5$1@dont-email.me> |
| In reply to | #13322 |
Bill Cunningham <nospam@nspam.invalid> wrote:
> "John McCue" <jmccue@jmclin0.bstnma.east.verizon.net> wrote in
> > Check your if statements :)
> > Not sure if that is your issue but best to validate the
> > if statements, esp the equal ones.
> ...
> What do you mean validate IFs ?
He means that you are using "assignment" operators, not "comparison"
operators, in most of your if statements. I.e.:
if (pp = NULL) {
This assigns NULL to the variable pp.
You likely want:
if (pp == NULL) {
which checks pp for equality to NULL.
Note, a way to get the compiler to complain about this style for you is
to reverse the two items in the if. Write it this way:
if (NULL == pp) {
or
if (5 == variable) {
Then, if you leave off an = sign, you'll get a compile error about
invalid assignment.
[toc] | [prev] | [next] | [standalone]
| From | Richard Kettlewell <rjk@greenend.org.uk> |
|---|---|
| Date | 2015-01-06 20:11 +0000 |
| Message-ID | <wwvtx03acuj.fsf@l1AntVDjLrnP7Td3DQJ8ynzIq3lJMueXf87AxnpFoA.invalid> |
| In reply to | #13323 |
Rich <rich@example.invalid> writes:
> He means that you are using "assignment" operators, not "comparison"
> operators, in most of your if statements. I.e.:
>
> if (pp = NULL) {
>
> This assigns NULL to the variable pp.
>
> You likely want:
>
> if (pp == NULL) {
>
> which checks pp for equality to NULL.
>
> Note, a way to get the compiler to complain about this style for you is
> to reverse the two items in the if. Write it this way:
>
> if (NULL == pp) {
> or
> if (5 == variable) {
>
> Then, if you leave off an = sign, you'll get a compile error about
> invalid assignment.
Compile with ‘gcc -Wall -Wextra -Werror’ and the compiler will spot the
error automatically, without any need to write the code in a bizarre
way.
--
http://www.greenend.org.uk/rjk/
[toc] | [prev] | [next] | [standalone]
| From | Rich <rich@example.invalid> |
|---|---|
| Date | 2015-01-06 21:22 +0000 |
| Message-ID | <m8hjlq$s9k$1@dont-email.me> |
| In reply to | #13324 |
Richard Kettlewell <rjk@greenend.org.uk> wrote:
> Rich <rich@example.invalid> writes:
> > He means that you are using "assignment" operators, not "comparison"
> > operators, in most of your if statements. I.e.:
> >
> > if (pp = NULL) {
> >
> > This assigns NULL to the variable pp.
> >
> > You likely want:
> >
> > if (pp == NULL) {
> >
> > which checks pp for equality to NULL.
> >
> > Note, a way to get the compiler to complain about this style for you is
> > to reverse the two items in the if. Write it this way:
> >
> > if (NULL == pp) {
> > or
> > if (5 == variable) {
> >
> > Then, if you leave off an = sign, you'll get a compile error about
> > invalid assignment.
> Compile with ?gcc -Wall -Wextra -Werror? and the compiler will spot the
> error automatically, without any need to write the code in a bizarre
> way.
Did not know those switches would warn about that. Thanks.
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2015-01-06 18:08 -0500 |
| Message-ID | <m8hpst$sap$1@speranza.aioe.org> |
| In reply to | #13324 |
"Richard Kettlewell" <rjk@greenend.org.uk> wrote in message
news:wwvtx03acuj.fsf@l1AntVDjLrnP7Td3DQJ8ynzIq3lJMueXf87AxnpFoA.invalid...
> Compile with 'gcc -Wall -Wextra -Werror' and the compiler will spot the
> error automatically, without any need to write the code in a bizarre
> way.
Well I've never heard of '-Wextra'. Evidentually I need to start
using -Wall more. I wasn't sure if this library would be on topic over in
clc. It must be being C is concerned.
Bill
[toc] | [prev] | [next] | [standalone]
| From | Richard Kettlewell <rjk@greenend.org.uk> |
|---|---|
| Date | 2015-01-07 09:20 +0000 |
| Message-ID | <wwvlhlf9cc2.fsf@l1AntVDjLrnP7Td3DQJ8ynzIq3lJMueXf87AxnpFoA.invalid> |
| In reply to | #13328 |
"Bill Cunningham" <nospam@nspam.invalid> writes: > "Richard Kettlewell" <rjk@greenend.org.uk> wrote: >> Compile with 'gcc -Wall -Wextra -Werror' and the compiler will spot >> the error automatically, without any need to write the code in a >> bizarre way. > > Well I've never heard of '-Wextra'. I recommend spending some time reading the compiler manual section on warnings. (The same goes for anyone else attempting to program in C who doesn’t know about these warnings options.) -- http://www.greenend.org.uk/rjk/
[toc] | [prev] | [next] | [standalone]
| From | Mark Blair <mblair@quantumdata.com> |
|---|---|
| Date | 2015-01-06 14:14 -0600 |
| Message-ID | <m8hfn8$ado$1@dont-email.me> |
| In reply to | #13322 |
On 1/6/2015 1:54 PM, Bill Cunningham wrote:
> "John McCue" <jmccue@jmclin0.bstnma.east.verizon.net> wrote in
>
>> Check your if statements :)
>> Not sure if that is your issue but best to validate the
>> if statements, esp the equal ones.
>
> The thing is I know nothing hardly about this API. Am I even using the
> functions as they should be used. Where pointers are asked for should I be
> passing them and not what is being pointed too? What do you mean validate
> IFs ?
>
> Bill
>
>
You've been posting to comp.lang.c for years! Wasn't John McCue's clue
enough? You're doing an *ASSIGNMENT* ("=") when you should be doing a
boolean equals ("==") test!
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2015-01-06 18:05 -0500 |
| Message-ID | <m8hpnt$rmo$1@speranza.aioe.org> |
| In reply to | #13325 |
"Mark Blair" <mblair@quantumdata.com> wrote in message
news:m8hfn8$ado$1@dont-email.me...
> You've been posting to comp.lang.c for years! Wasn't John McCue's clue
> enough? You're doing an *ASSIGNMENT* ("=") when you should be doing a
> boolean equals ("==") test!
You seem to be reading what you want to see in posts. Have I not said
"It's been a while..." Have I not said before. "I have quite many things to
do."? What are you trying to say other than you haven't been paying
attention for years? Finally someone answers over here. Well in clc they've
pointed things out to me and I've changed it and proceeded a bit further in
the code.
Bill
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2015-01-06 18:12 -0500 |
| Message-ID | <m8hq4q$tbj$1@speranza.aioe.org> |
| In reply to | #13325 |
"Mark Blair" <mblair@quantumdata.com> wrote in message
news:m8hfn8$ado$1@dont-email.me...
> "...Wasn't John McCue's clue enough?..."
Clue? What clue? He said, "Check your if statements :)
*Not sure if that is your issue* but best to validate the
if statements, esp the equal ones."
That sounds to me like he's a little unsure also. I wouldn't call that
any intentional clue.
Bill
[toc] | [prev] | [next] | [standalone]
| From | Rich <rich@example.invalid> |
|---|---|
| Date | 2015-01-06 23:37 +0000 |
| Message-ID | <m8hrk3$r1k$2@dont-email.me> |
| In reply to | #13329 |
Bill Cunningham <nospam@nspam.invalid> wrote: > "Mark Blair" <mblair@quantumdata.com> wrote in message > news:m8hfn8$ado$1@dont-email.me... > > "...Wasn't John McCue's clue enough?..." > Clue? What clue? He said, "Check your if statements :) > *Not sure if that is your issue* but best to validate the > if statements, esp the equal ones." > That sounds to me like he's a little unsure also. I wouldn't call > that any intentional clue. > Bill He was trying to give you a hint (i.e., to scrutinize your if statements) rather than handing you the answer on a silver platter. When I first glanced at your post, I missed the assignment vs. equals issue. When Jon McCue's message arrived, I looked again, and immediately saw the issue (hadn't looked closely enough for the first glance).
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2015-01-06 18:44 -0500 |
| Message-ID | <m8hs0s$2dm$1@speranza.aioe.org> |
| In reply to | #13330 |
"Rich" <rich@example.invalid> wrote in message
news:m8hrk3$r1k$2@dont-email.me...
> He was trying to give you a hint (i.e., to scrutinize your if
> statements) rather than handing you the answer on a silver platter.
>
> When I first glanced at your post, I missed the assignment vs. equals
> issue. When Jon McCue's message arrived, I looked again, and
> immediately saw the issue (hadn't looked closely enough for the first
> glance).
Ok I probably typed one thinking it was the other. I haven't dealt with
C for a while. The code now gets to where there's a problem with either
pcap_activate or the "datalink" function. I am going to give this -Wall a
try. And maybe -Wextra that's a new one on me.
Bill
[toc] | [prev] | [standalone]
Back to top | Article view | comp.os.linux.misc
csiph-web