www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/20/23:41:52

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A simple program that works except under GDB...
Date: Thu, 20 Mar 1997 13:28:22 -0500
Organization: Cornell University
Lines: 77
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <333181C6.7692@cornell.edu>
References: <33317551 DOT 4DE2 AT isen DOT fr>
NNTP-Posting-Host: 128
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Regis BOSSUT wrote:
> 
> Hi all!
> 
> I wrote a small program to find out my LAN card MAC address, based on
> the example provided by Microsoft, using Netbios, adapted with help of
> intwin.hlp (interrupt 0x5c).
> 
> It works fine when run as is, but gives incorrect results when run
> under GDB. Seems that memory is used differently, but I don't see why.
> 

> 
> _____ Start of adapt.c _____
> #include <stdio.h>
> #include <stdlib.h>
> #include <dpmi.h>
> #include <go32.h>
> 
> #define BYTE unsigned char
> #define WORD unsigned short
> #define DWORD unsigned int
> 
> typedef struct {
> BYTE  ncb_command;
> #define NCBASTAT 0x33
> BYTE  ncb_retcode, ncb_lsn, ncb_num;
> char *ncb_buffer; WORD  ncb_length;
> BYTE  ncb_callname[16], ncb_name[16];
> BYTE  ncb_rto, ncb_sto;
> int   (*ncb_post)();
> BYTE  ncb_lana_num, ncb_cmd_cplt;
> char *ncb_vname;
> BYTE  ncb_vnamelen;
> BYTE  ncb_reserve[9];
> } NCB;
> 

i don't know what you mean "memory is used differently". however, when 
you are dealing with 16-bit interfaces that expect certain data at 
certain offsets (into the struct), you need to pack your structs to 
override the default 32 bit alignment of struct members.
here is how i did it:

/* Network Control Block (NCB) */
typedef struct {
    BYTE     cmd;
    BYTE     ret_code;
    BYTE     lsn;
    BYTE     ncb_num;
    WORD     io_off;
    WORD     io_seg;
    WORD     len;
    BYTE     rmt_name[NBNAMELENGTH];
    BYTE     lcl_name[NBNAMELENGTH];
    BYTE     rec_to;
    BYTE     snd_to;
    WORD     post_off;
    WORD     post_seg;
    BYTE     lana;
    BYTE     cmp_code;
    BYTE     rsrv[14];
}__attribute__((packed)) NCB;

basically, the sizeof your ncb struct has to be 64. check yours. BTW, why 
is there a #define in the midle of the struct?

further, you cannot pass djgpp pointers (32-bit protected mode) to 16 bit 
interfaces, you need to allocate dos memory (or use the transfer buffer; 
see the FAQ) and communicate with netbios via that memory block.

if you promise not to advertise to the world how crappy a page it is, you 
can take a look at:

http://www.people.cornell.edu/pages/asu1/netbios.htm

-- sinan.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019