Δημοσιεύτηκε: 15 Μαρ 2012, 02:38
από migf1
utnubu έγραψε:Καλησπέρα,
προσπαθώ να τραβήξω κάποιες πληροφορίες από ένα sip πακέτο με τον παρακάτω κώδικα.
Αυτό που παίρνω όταν τρέχω τον κώδικα είναι segmantation fault.
Αν κάποιος μπορεί να βοηθήσει,θα είμαι ευγνώμων. :bow:
Spoiler: show
Κώδικας: Επιλογή όλων


char * tch; /* Parsing pointer for strtok function */
char * from; /* "From" pointer */
char * contact; /* "Contact" pointer */
char * user; /* "User" pointer */
char * callid; /* "Call-ID" pointer */
char * payload; /* Packet's Payload */
tch = strtok (payload,"<>;\n\"");
while (tch != NULL)
{
if (strncmp(tch, "From",4)==0) /* Comparation of first 4 chars to "From" and if so collect it*/
{
tch = strtok (NULL, "<>;\n\"");
from = tch;
printf ("\n SIP From: %s \n", from);
}
if (strncmp(tch, "Contact",7)==0) /* Comparation of first 7 chars to "Contact" and if so collect it*/
{
tch = strtok (NULL, "<>;\n\"");
contact = tch;
printf (" SIP Contact: %s \n", contact);
}
if (strncmp(tch, "Authorization",13)==0) /* Comparation of first 13 chars to "Authorization" and if so collect it*/
{
tch = strtok (NULL, "<>;\n\"");
user = tch;
printf (" SIP User: %s \n", user);
}
if (strncmp(tch, "Call-ID",7)==0) /* Comparation of first 7 chars to "Call-ID" and if so collect it*/
{
callid = tch;
printf (" %s \n", callid);
}
tch = strtok (NULL, "<>;\n\"");
}

Είμαι πολύ κουρασμένος για να κοιτάξω τώρα τον κώδικα, αλλά αυτό εδώ...

Κώδικας: Επιλογή όλων

...
char * payload; /* Packet's Payload */
tch = strtok (payload,"<>;\n\"");
...

φωνάζει "seg fault"!

Το payload πρέπει να είναι non-NULL στην 1η κλήση της strtok() (και NULL στις υπόλοιπες)... εσύ το περνάς με undefined content στην 1η κλήση της strtok().