-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirc.txt
More file actions
202 lines (177 loc) · 13.3 KB
/
irc.txt
File metadata and controls
202 lines (177 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
-SOCKET
Soket veya Socket bilgisayar işlemleri veya bilgisayarlar arası işlemler için kullanılan haberleşme dosyalarıdır.
-Soket programlama nedir?
Soket programlama temel olarak alıcı ve gönderici arasındaki iletişim yönetmek için kullanılan programlama tekniğine denir.
*Soket programlama bilgisayarlar arası veri haberleşmesinde kullanılır.
*HTTP, FTP, SMTP gibi iletişim protokolleri soket yapısı üzerine inşa edilmiştir.
*Ayrıca kendi kurallarımızı belirleyerek chat-sohbet, dosya transferi gibi uygulamalar yapılabilir.
-Basit soket örneği:
<-SERVER->------------------------------------------------------------------V
#include <iostream>
#include <cstring>
#include <arpa/inet.h>
#include <unistd.h>
int main() {
// Soket değişkenleri
int serverSocketFD, clientSocket;
sockaddr_in serverAddr, clientAddr;
socklen_t clientAddrSize = sizeof(clientAddr);
char buffer[1024];
// Sunucu soketini oluşturma
serverSocketFD = socket(AF_INET, SOCK_STREAM, 0); // bir fd dönüyor.
/*
tanım : int sockfd = socket(domain, type, protocol)
socket: Br soket nesnesi oluşturur ve bu nesneye bir dosya tanımlayıcısı (file descriptor) atar. Bu dosya tanımlayıcısı, soket üzerinden iletişim kurmak ve işlem yapmak için kullanılır.
AF_INET: Adres ailesi (address family) olarak kullanılır ve IPv4 adreslerini kullanarak ağ iletişimi sağlar.
SOCK_STREAM: İletişimin yüksek güvenilirlik ve bağlantı tabanlı olduğunu belirtir. Bu, TCP (Transmission Control Protocol) protokolünü kullanarak güvenilir ve sıralı veri iletişimini ifade eder. İstemciler ve sunucular genellikle SOCK_STREAM kullanarak birbirleriyle iletişim kurarlar.
0 (protocol): Tip parametresini belirtilen adres ailesi ve soket türü ile ilişkilendirmek için kullanılır. Bu genellikle kullanılan bir yöntemdir ve çoğu zaman bu parametreyi 0 olarak bırakabilirsiniz.
*/
if (serverSocketFD == -1) {
std::cerr << "Error creating server socket." << std::endl;
return 1;
}
// Sunucu adresini ayarlama
serverAddr.sin_family = AF_INET; //soket adresinin aile türünü belirtir. Burada AF_INET, IPv4 adres ailesini temsil eder. Sunucu, bu aile türünü kullanarak IPv4 adresleri ile iletişim kurar.
serverAddr.sinserverPort = htons(8080); //sunucunun hangi port üzerinden bağlantıları dinleyeceğini belirtir. Burada htons işlevi (host to network short), 16 bitlik bir değeri ağ baytlarına (network byte order) dönüştürür. Bu nedenle 8080 portunu ağ baytlarına dönüştürerek kullanılır.
serverAddr.sin_addr.s_addr = INADDR_ANY; //sunucunun hangi IP adresini dinleyeceğini belirtir. INADDR_ANY, sunucunun mevcut tüm ağ arayüzleri üzerinden gelen bağlantıları kabul edeceği anlamına gelir. Bu, sunucunun herhangi bir IP adresi ile gelen bağlantıları dinlemesini sağlar ve bu şekilde sunucunun herhangi bir ağ arabirimi veya IP adresine bağlanmasına izin verir.
// Sunucu soketini bağlama
if (bind(serverSocketFD, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) == -1)
{
std::cerr << "Error binding server socket." << std::endl;
return 1;
}
/*
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
bind: Bu işlev, sunucu soketini bir IP adresi ve port ile ilişkilendirir. Bu sayede sunucu, belirtilen IP adresi ve port üzerinden gelen bağlantıları dinlemeye başlar.
serverSocketFD(sockfd): Bağlama işlemi gerçekleştirilecek olan sunucu soketini temsil eder. Bu soket, önceden socket işlemini kullanarak oluşturulmuş bir sokettir.
(struct sockaddr *)&serverAddr: bind işlevinin ikinci argümanı, sockaddr türünde bir adresi (address) belirtir. Bu tür, IP adresi ve port bilgilerini içerir. Ancak, bind işlevi sockaddr türünden bir yapıyı bekler, bu nedenle serverAddr adlı bir sockaddr_in yapısının tür dönüşümü kullanılır. sockaddr_in yapısı, IPv4 adreslerini ve portlarını temsil eden özel bir yapıdır.
sizeof(serverAddr)(socklen_t addrlen): bind işleminin üçüncü argümanı, serverAddr yapısının boyutunu belirtir. Bu, işlemin serverAddr yapısının tam boyutunu bildiğini ve bu yapıyı veri hedefine kopyalayabileceği anlamına gelir.
*/
// Bekleme ve bağlantı kabul etme
listen(serverSocketFD, 5);// 5 -> eşzamanlı olarak kabul edilebilecek bağlantıların maksimum sayısını belirtir.
std::cout << "Server is listening on port 8080..." << std::endl;
// İstemci bağlantısını kabul etme
clientSocket = accept(serverSocketFD, (struct sockaddr *)&clientAddr, &clientAddrSize);
/*
Sunucu tarafında gelen istemci bağlantılarını kabul etmek ve bir yeni soket oluşturarak iletişim kurmaya başlamak için kullanılır. İşte bu kodun açıklamaları:
accept: Bu işlev, sunucu tarafındaki soketin beklemekte olan bağlantıları kabul etmesini sağlar. Yani, istemcilerin sunucuya bağlanma isteğini kabul eder ve bir yeni soket oluşturur. Bu yeni soket, belirli istemci ile iletişim kurmak için kullanılır.
serverSocketFD: Bağlantıları kabul etmek için kullanılan sunucu soketini temsil eder. Bu soket, daha önce socket, bind ve listen işlevleri ile oluşturulmuş bir sokettir.
(struct sockaddr *)&clientAddr: Bağlantı isteğini yapan istemcinin bilgilerini içeren bir yapıdır. accept işlemi bu bilgileri clientAddr yapısına kopyalar. Bu bilgiler, istemci ile iletişim kurmak için kullanılır.
&clientAddrSize: Bu, clientAddr yapısının boyutunu belirtir ve işlevin bu yapının ne kadar yer kapladığını bilmesini sağlar.
accept işlemi, bir istemcinin bağlantı isteğini kabul eder, yeni bir soket oluşturur ve bu soketi kullanarak sunucu ile istemci arasında iletişim kurmaya başlar. Bu nedenle, her yeni istemci bağlantısı için accept işlemi çağrılır ve yeni soket oluşturulur. Bu yeni soket, sunucu ile belirli bir istemci arasındaki iletişimi yönetir.
*/
if (clientSocket == -1) {
std::cerr << "Error accepting client connection." << std::endl;
return 1;
}
// İstemciden gelen veriyi okuma ve ekrana yazdırma
recv(clientSocket, buffer, sizeof(buffer), 0);
std::cout << "Client says: " << buffer << std::endl;
// İstemciye yanıt gönderme
const char *response = "Hello from server!";
send(clientSocket, response, strlen(response), 0);
// Soketleri kapatma
close(clientSocket);
close(serverSocketFD);
return 0;
}
<-SERVER->------------------------------------------------------------------^
<-CLIENT->------------------------------------------------------------------V
#include <iostream>
#include <cstring>
#include <arpa/inet.h>
#include <unistd.h>
int main() {
// Soket değişkeni
int clientSocket;
sockaddr_in serverAddr;
char buffer[1024];
// İstemci soketini oluşturma
clientSocket = socket(AF_INET, SOCK_STREAM, 0);
if (clientSocket == -1) {
std::cerr << "Error creating client socket." << std::endl;
return 1;
}
// Sunucu adresini ayarlama
serverAddr.sin_family = AF_INET;
serverAddr.sinserverPort = htons(8080);
inet_pton(AF_INET, "127.0.0.1", &(serverAddr.sin_addr));
// Sunucuya bağlanma
if (connect(clientSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) == -1) {
std::cerr << "Error connecting to server." << std::endl;
return 1;
}
/*
connect: Bu işlev, istemci tarafındaki soketin belirli bir sunucu ile bağlantı kurmasını sağlar. İstemci, sunucu ile iletişim kurmak istediğinde connect işlemini kullanarak bağlantıyı başlatır.
clientSocket: Bağlantıyı başlatan istemci soketini temsil eder. Bu soket, daha önce socket işlevi ile oluşturulmuş bir sokettir.
(struct sockaddr *)&serverAddr: Bağlanılacak sunucunun adres bilgilerini içeren bir yapıdır. connect işlemi bu yapıyı kullanarak sunucu ile iletişim kurar.
sizeof(serverAddr): Sunucu adres yapısının boyutunu belirtir. Bu, connect işleminin sunucu adres yapısını doğru şekilde işlemesini sağlar.
connect işlemi, istemcinin belirli bir sunucuya bağlanmasını sağlar. Bu işlem, sunucu adresini ve port numarasını kullanarak belirli bir sunucu ile iletişim kurar. Bağlantı başarıyla kurulduğunda, istemci ve sunucu arasında veri alışverişi yapabilirler.
*/
// Sunucuya veri gönderme
const char *message = "Hello from client!";
send(clientSocket, message, strlen(message), 0);
// Sunucudan gelen yanıtı okuma ve ekrana yazdırma
recv(clientSocket, buffer, sizeof(buffer), 0);
std::cout << "Server says: " << buffer << std::endl;
// Soketi kapatma
close(clientSocket);
return 0;
}
<-CLIENT->------------------------------------------------------------------^
Commands
http://www.csun.edu/~webteach/mirc/commands.html
join #channel to join a channel
part #channel to leave a channel
leave #channel to leave a channel
exit to exit IRC
bye to exit IRC
quit to exit IRC
nick newnick nickname. changes your IRC nickname for instance /nick Dragon . This would make me appear as Dragon
msg nickname message here text sends a private msg to someone for example if I wanted to talk to Peter in private I would type /msg peter hey do you have a minute?
whois nickname gives the persons profile.ini information to you.
whowas nickname tells the last person that used that nickname.
who #channel tells who is on that channel without you having to be on it. So if I wanted to know who was on #room861 before entering it I would type /who #room861
who tells who is on the whole irc server you are on. If you are on one of the bigger servers like undernet, you might find yourself getting disconnected if you use this command. Basically the names list on the busy servers are sooo long that it will flood you off the server is you try listing it.
list gives all channels on IRC (very LONG list on some servers can again flood you off)
flush stops the flow of a long listing of channels. If you feel the listing is too long and you might get flooded off, just type /flush quickly and that will stop the process.
notice nickname text sends a highlighted message to a person you choose. For instance /notice peter hey you how is it going? Would send a message to peter's screen, but would not open a private message window like /msg. (The exception to this rule is if the user has setup their client software to force a private window to open).
topic #channel text changes topic on the channel. The topic is found by looking way up to the top of the channel screen, it is much like a title for the channel, and often important information about the channel will be placed there. Often Channel Operators will set the topic up so only other operators can change it.
mode #channel +o nick gives channel ops to a person ( you must have ops on the channel to give ops ). So if I was an op on #room861 and wanted to give operators status to Don I would type /mode #room861 +o don
kick #channel nick kicks person off channel (you must have ops to kick ) This command should only be used when necessary, but be warned, some inexperienced ops go on powertrips and start kicking people randomly. For you this usually boils down to just leaving the channel and finding one where the ops actually have a life.
dcc send nick filename sends a file from your dir to another person on IRC
dcc get nick receive a file from another person
dcc chat nick starts a chat with a person on IRC
me actionhere does an action e.g. /me says hi is *nickname says hi*
query nick starts a private conversation with that person
query ends conversation
invite nick invites a person to an invite only channel
ctcp nick finger gives finger info on a person
ping nick tests lag between you and another person's server
ignore nick all Ignores an annoying person
ignore nick none clears your ignore list
1. `socket`: Creates a socket and returns a file descriptor used for network communication.
2. `close`: Closes the specified file descriptor.
3. `setsockopt`: Sets socket options.
4. `getsockname`: Retrieves the address of a socket and returns it in a struct sockaddr data structure.
5. `getprotobyname`: Gets the protocol number based on the protocol name.
6. `gethostbyname`: Gets the IP address based on the host name.
7. `getaddrinfo`: Used to obtain information about a host and service based on host name and service name.
8. `freeaddrinfo`: Frees the memory allocated for the addrinfo structure created by getaddrinfo.
9. `bind`: Associates a socket with an address and port.
10. `connect`: Establishes a connection to a server using a socket.
11. `listen`: Marks the socket as a passive socket and starts listening for incoming connections.
12. `accept`: Accepts an incoming connection and returns a new socket descriptor for communication.
13. `htons`: Converts a 16-bit value to network byte order.
14. `htonl`: Converts a 32-bit value to network byte order.
15. `ntohs`: Converts a 16-bit value to host byte order.
16. `ntohl`: Converts a 32-bit value to host byte order.
17. `inet_addr`: Converts an IPv4 address from a string to an integer.
18. `inet_ntoa`: Converts an IPv4 address from an integer to a string.
19. `send`: Sends data from a socket.
20. `recv`: Receives data from a socket.
21. `signal`: Sets a signal handler function.
22. `lseek`: Changes the file offset of an open file.
23. `fstat`: Retrieves information about a file.
24. `fcntl`: Performs various operations on a file descriptor.
25. `poll`: Monitors multiple file descriptors to determine which ones are ready for I/O operations.