This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Help with Pointers - Need to tweak a little C function

Discussion of Eggdrop's code and module programming in C.
Post Reply
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Help with Pointers - Need to tweak a little C function

Post by awyeah »

This is not the most accurate place to ask, but anyway this is related to C, so anyway here goes.

I am using anope services (ChanServ, NickServ... etc) www.anope.org on my IRC network (bahamut-1.8.3) and wanted to modify their accest lists so that they also show ip address infront of nicknames, the last seen ip address of that registered nick, like DALnet has in their aop/sop/akick lists.

I modified the following code:

Code: Select all

static int xop_list(User * u, int index, ChannelInfo * ci, int *sent_header,
int xlev, int xmsg) {

ChanAccess *access = &ci->access[index];
NickAlias *na;

if (!access->in_use || access->level != xlev)
return 0;

if (!*sent_header) {
notice_lang(s_ChanServ, u, xmsg, ci->name);
*sent_header = 1;
}

notice_lang(s_ChanServ, u, CHAN_XOP_LIST_FORMAT, index + 1,
access->nc->display, na->last_usermask);
return 1;
}
To this code, when I asked a project developer of anope team:

Code: Select all

static int xop_list(User * u, int index, ChannelInfo * ci,
int *sent_header, int xlev, int xmsg)
{

NickCore *nc;
ChanAccess *access = &ci->access[index];
NickAlias *na = findnick(nc->display);

if (!access->in_use || access->level != xlev) {
return 0;
}
if (!*sent_header) {
notice_lang(s_ChanServ, u, xmsg, ci->name);
*sent_header = 1;
}

if (!(access->nc->na->last_usermask)) {
notice_lang(s_ChanServ, u, CHAN_XOP_LIST_FORMAT, index + 1,
access->nc->display, "(no record for userhost has been found)");
}

else {
notice_lang(s_ChanServ, u, CHAN_XOP_LIST_FORMAT, index + 1,
access->nc->na->last_usermask);

}
return 1;
}

This is the generated error by the compiler:
$ make
sh version.sh
gcc -O2 -Wall -g -c chanserv.c
chanserv.c: In function `xop_list':
chanserv.c:3621: structure has no member named `na'
chanserv.c:3628: structure has no member named `na'
chanserv.c:3611: warning: unused variable `na'
chanserv.c:3610: warning: `nc' might be used uninitialized in this function
*** Error code 1
If anyone is aware of this network services and know's C, I would really appreciate if you could help me out here, especially in these pointers.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

alright. took me 30 secs to find the errors (maybe cause im used to getting errors :p )

first of all:

Code: Select all

NickCore *nc; 
ChanAccess *access = &ci->access[index]; 
NickAlias *na = findnick(nc->display); 
both nc and na are empty because you didnt initialize nc (na is empty because you tried to find an empty nick with value null - nothing)

hence these two errors:

Code: Select all

chanserv.c:3611: warning: unused variable `na' 
chanserv.c:3610: warning: `nc' might be used uninitialized in this function 
second:

Code: Select all

if (!(access->nc->na->last_usermask)) {
&

Code: Select all

access->nc->na->last_usermask
the structure access has a member called nc but nc doesnt have a member called na. maybe you should check the source files to see how the structure ChanAccess looks like. you should find a reference to another structure for nc so you can check what the members in that structure are...

hence these two errors:

Code: Select all

chanserv.c:3621: structure has no member named `na' 
chanserv.c:3628: structure has no member named `na' 
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

I fixed the code with another technique. The source code compiles fine without an error or a single warning. But sometimes in between while displaying access lists services crashes for no reason. :roll:

Never encountered this type of error before. Showed the code to alot of people logicially it looks fine and works fine but sometimes it doesn't. I will check the services.core file generated by gdb.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Post Reply