Twoim problemem jest to, że powszechną NICOŚĆ mylisz z osobistą PUSTKĄ
/**********Lab2 ****************/
void error(int code, char *reason) {
printf("ERROR code = %d, \"%s\"\n",code,reason);
getchar();
exit(code);}
void reset_ncb(NCB *ncbPtr) {
memset(ncbPtr, '\0', sizeof(struct _NCB));
memset(ncbPtr->ncb_callname, ' ' , NCBNAMSZ);
memset(ncbPtr->ncb_name, ' ' , NCBNAMSZ);}
UCHAR ResetAdapter(NCB *ncbPtr) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command= NCBRESET;
ncbPtr->ncb_lsn = 0x00;
ncbPtr->ncb_callname[0] = 1;
ncbPtr->ncb_callname[2] = 1;
//ncbPtr->ncb_lana_num = lana_num;
return Netbios(ncbPtr);
}
UCHAR AddName(NCB *ncbPtr, UCHAR *taker) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBADDNAME;
strcpy(ncbPtr->ncb_name,taker);
ncbPtr->ncb_name
[strlen(taker)] = ' ';
return Netbios(ncbPtr);}
UCHAR DeleteName(NCB *ncbPtr, UCHAR *added_name, UCHAR number_taker) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBDELNAME;
strcpy(ncbPtr->ncb_name, added_name);
ncbPtr->ncb_name
[strlen(added_name)] = ' ';
ncbPtr->ncb_lana_num = lana_num;
return Netbios(ncbPtr);}
/**************Lab3 ************/
UCHAR SendDatagram(NCB *ncbPtr, char num, char *name, char *message) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBDGSEND;
ncbPtr->ncb_lana_num = lana_num;
ncbPtr->ncb_num = num;
strcpy(ncbPtr->ncb_callname, name);
ncbPtr->ncb_callname
[strlen(name)] = ' ';
ncbPtr->ncb_buffer = message;
ncbPtr->ncb_length = strlen(message);
return Netbios(ncbPtr);}
UCHAR ReceiveDatagram
(NCB *ncbPtr, char num, char* message, WORD buff_size) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBDGRECV;
ncbPtr->ncb_lana_num = lana_num;
ncbPtr->ncb_num = 0xFF;
ncbPtr->ncb_buffer = message;
ncbPtr->ncb_length = buff_size;
return Netbios(ncbPtr);}
/************* Lab4**************/
UCHARSendDatagramBroadcast(NCB *ncbPtr, char num, char *name, char *message) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBDGSENDBC;
ncbPtr->ncb_lana_num = lana_num;
ncbPtr->ncb_num = num;
ncbPtr->ncb_buffer = message;
ncbPtr->ncb_length = strlen(message);
return Netbios(ncbPtr); }
UCHAR ReceiveDatagramBroadcast(NCB *ncbPtr, char num, char* message, WORD buff_size) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBDGRECVBC;
ncbPtr->ncb_lana_num = lana_num;
ncbPtr->ncb_num = num;
ncbPtr->ncb_buffer = message;
ncbPtr->ncb_length = buff_size;
return Netbios(ncbPtr);}
/************ Lab5 **********/
UCHAR AddGroupName(NCB *ncbPtr, UCHAR *name) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBADDGRNAME;
ncbPtr->ncb_lana_num = lana_num;
strcpy(ncbPtr->ncb_name, name);
ncbPtr->ncb_name[strlen(name)] = ' ';
return Netbios(ncbPtr);}
/*********** Lab6 ***************/
UCHAR CallSession(NCB *ncbPtr, UCHAR *local_name, UCHAR *remote_name) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBCALL;
ncbPtr->ncb_lana_num = lana_num;
strcpy(ncbPtr->ncb_name, local_name);
ncbPtr->ncb_name
[strlen(local_name)] = ' ';
strcpy(ncbPtr->
ncb_callname, remote_name);
ncbPtr->ncb_callname
[strlen(remote_name)] = ' ';
ncbPtr->ncb_rto = 0;
ncbPtr->ncb_sto = 0;
return Netbios(ncbPtr);}
UCHAR ListenSession
(NCB *ncbPtr, UCHAR *session_name, UCHAR *remote_name) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBLISTEN;
ncbPtr->ncb_lana_num = lana_num;
strcpy(ncbPtr->
ncb_name, session_name);
ncbPtr->ncb_name
[strlen(session_name)] = ' '
strcpy(ncbPtr->
ncb_callname, remote_name);
ncbPtr->ncb_callname
[strlen(remote_name)] = ' ';
ncbPtr->ncb_rto = 0;
ncbPtr->ncb_sto = 0;
return Netbios(ncbPtr);}
UCHAR HangUpSession(NCB *ncbPtr, UCHAR id_session) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBHANGUP;
ncbPtr->ncb_lana_num = lana_num;
ncbPtr->ncb_lsn = id_session;
return Netbios(ncbPtr);}
UCHAR SendSession(NCB *ncbPtr, UCHAR id_session, char *message) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBSEND;
ncbPtr->ncb_lana_num = lana_num;
ncbPtr->ncb_num = id_session;
ncbPtr->ncb_lsn = id_session;
ncbPtr->ncb_buffer = message;
ncbPtr->ncb_length = strlen(message);
return Netbios(ncbPtr);
}
UCHAR ReceiveSession(NCB *ncbPtr, UCHAR id_session, char* message, WORD buff_size) {
reset_ncb(ncbPtr);
ncbPtr->ncb_command = NCBRECV;
ncbPtr->
ncb_lana_num = lana_num;
ncbPtr->ncb_lsn = id_session;
ncbPtr->ncb_buffer = message;
ncbPtr->ncb_length = buff_size;
return Netbios(ncbPtr);}
/**********lab7************/
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#define check_error(what) (err = what) != 0
void error(int code,int err, char *reason) {
printf("ERROR code = %d, returned value = %d, errno = %d, \"%s\"\n", code, err, errno, reason); WSACleanup();
getchar(); exit(code);}
int main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
char hostname[512];
struct hostent *h, *h2;
struct in_addr addr;
wVersionRequested =
MAKEWORD(2, 2);
if(check_error(WSAStartup(
wVersionRequested, &wsaData))) error(1, err, "WSAStartup");
puts("Data from WSADATA:");
printf(" iMaxSockets = %d\n", wsaData.iMaxSockets);
printf(" iMaxUdpDg = %d\n", wsaData.iMaxUdpDg);
printf(" lpVendorInfo = %d\n", wsaData.lpVendorInfo);
printf(" szDescription = \"%s\"\n", wsaData.szDescription);
printf(" wVersion = %d\n", LOBYTE(wsaData.wVersion));
printf(" wVersion = %d\n", HIBYTE(wsaData.wVersion));
printf(" wHighVersion = %d\n", LOBYTE(wsaData.wHighVersion));
printf(" wHighVersion = %d\n\n", HIBYTE(wsaData.wHighVersion));
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
{error(2, 0, "Could not find a usable version of Winsock.dll");}
memset(hostname, '\0', sizeof(hostname));
if(gethostname(hostname, sizeof(hostname)) != 0) error(3, 0, "gethostname");
puts("Data from gethostname:");
printf(" Hostname = \"%s\"\n\n",hostname);
if((h = gethostbyname(hostname)) == NULL) error(4, 0, "gethostbyname");
puts("Data from gethostbyname:");
printf(" Official name of the host = \"%s\"\n", h->h_name);
printf(" First IP address : %s\n", inet_ntoa(*((struct in_addr *)h->h_addr)));
printf(" First aliase = \"%s\"\n", h->h_aliases);
printf(" The length of the address in bytes = %d\n", h->h_length);
printf(" Address type in dec = %d\n\n", h->h_addrtype);
memset(hostname, '\0', sizeof(hostname));
strcpy(hostname, inet_ntoa(*((struct in_addr *)h->h_addr)));
...