((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)

0

Co oznacza:
[code]
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("socket");
exit(1);
}
[/code]
Dlaczego -1?
Co to jest (AF_INET, SOCK_STREAM, 0)?
Co to jest perror("socket");?

1

pocytuje troche mana ;>

[code]
RETURN VALUE
-1 is returned if an error occurs; otherwise the return
value is a descriptor referencing the socket.
[/code]
czyli.. funkcja ta zwraca -1 jesli wystapil blad...

teraz parametry:
[code]
bits/socket.h:#define AF_INET PF_INET
PF_INET IPv4 Internet protocols
[/code]
socket ma byc ustawiony do wykorzystania protokolu IPv4

[code]
SOCK_STREAM
Provides sequenced, reliable, two-way, connection-
based byte streams. An out-of-band data transmis­
sion mechanism may be supported.
[/code]
inaczej.. bedzie to socket obslugiwany przez protokol TCP ;>
(czyli juz mamy z tych dwoch parametrow info o tym ze jest to sock
TCP/IP)

[code]
The protocol specifies a particular protocol to be used
with the socket. Normally only a single protocol exists
to support a particular socket type within a given proto­
col family.
[/code]
czyli numer protokolu, ale jako z TCP/IP jest tylko jeden i nie ma zadnych "protokolow dzieci", tam zawsze musi byc 0 ;>

a teraz ostatnie
[code]
perror - print a system error message
The routine perror() produces a message on the standard
error output, describing the last error encountered during
a call to a system or library function. The argument
string s is printed first, then a colon and a blank, then
the message and a new-line.
[/code]
czyli... wyswietla podany tekst.. a potem info o zaistnialym bledzie ;>

1 użytkowników online, w tym zalogowanych: 0, gości: 1