Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pcom-laboratoare-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tudor-Andrei CORNESCU
pcom-laboratoare-public
Commits
403c2be3
Commit
403c2be3
authored
1 year ago
by
Ion-Dorinel FILIP (25005)
Browse files
Options
Downloads
Patches
Plain Diff
Added open_connection(...) helper to SMTP skel
parent
feb19cd2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lab10/Email/send_mail.c
+26
-12
26 additions, 12 deletions
lab10/Email/send_mail.c
with
26 additions
and
12 deletions
lab10/Email/send_mail.c
+
26
−
12
View file @
403c2be3
...
@@ -56,6 +56,25 @@ ssize_t read_line(int sockd, void *vptr, size_t maxlen)
...
@@ -56,6 +56,25 @@ ssize_t read_line(int sockd, void *vptr, size_t maxlen)
return
n
;
return
n
;
}
}
int
open_connection
(
char
*
host_ip
,
int
portno
,
int
ip_type
,
int
socket_type
,
int
flag
)
{
struct
sockaddr_in
serv_addr
;
int
sockfd
=
socket
(
ip_type
,
socket_type
,
flag
);
if
(
sockfd
<
0
)
error
(
"ERROR opening socket"
);
memset
(
&
serv_addr
,
0
,
sizeof
(
serv_addr
));
serv_addr
.
sin_family
=
ip_type
;
serv_addr
.
sin_port
=
htons
(
portno
);
inet_aton
(
host_ip
,
&
serv_addr
.
sin_addr
);
/* connect the socket */
if
(
connect
(
sockfd
,
(
struct
sockaddr
*
)
&
serv_addr
,
sizeof
(
serv_addr
))
<
0
)
error
(
"ERROR connecting"
);
return
sockfd
;
}
/**
/**
* Trimite o comanda SMTP si asteapta raspuns de la server. Comanda
* Trimite o comanda SMTP si asteapta raspuns de la server. Comanda
* trebuie sa fie in buffer-ul sendbuf. Sirul expected contine
* trebuie sa fie in buffer-ul sendbuf. Sirul expected contine
...
@@ -98,12 +117,7 @@ int main(int argc, char **argv) {
...
@@ -98,12 +117,7 @@ int main(int argc, char **argv) {
strncpy
(
server_ip
,
argv
[
1
],
INET_ADDRSTRLEN
);
strncpy
(
server_ip
,
argv
[
1
],
INET_ADDRSTRLEN
);
// TODO 1: creati socket-ul TCP client
// TODO 1: Conecteaza-te la server
// TODO 2: completati structura sockaddr_in cu
// portul si adresa IP ale serverului SMTP
// TODO 3: conectati-va la server
// se primeste mesajul de conectare de la server
// se primeste mesajul de conectare de la server
read_line
(
sockfd
,
recvbuf
,
MAXLEN
-
1
);
read_line
(
sockfd
,
recvbuf
,
MAXLEN
-
1
);
...
@@ -113,17 +127,17 @@ int main(int argc, char **argv) {
...
@@ -113,17 +127,17 @@ int main(int argc, char **argv) {
sprintf
(
sendbuf
,
"HELO localhost"
);
sprintf
(
sendbuf
,
"HELO localhost"
);
send_command
(
sockfd
,
sendbuf
,
"250"
);
send_command
(
sockfd
,
sendbuf
,
"250"
);
// TODO
4
: trimiteti comanda de MAIL FROM
// TODO
2
: trimiteti comanda de MAIL FROM
// TODO
5
: trimiteti comanda de RCPT TO
// TODO
3
: trimiteti comanda de RCPT TO
// TODO
6
: trimiteti comanda de DATA
// TODO
4
: trimiteti comanda de DATA
// TODO
7
: trimiteti e-mail-ul (antete + corp + atasament)
// TODO
5
: trimiteti e-mail-ul (antete + corp + atasament)
// TODO
8
: trimiteti comanda de QUIT
// TODO
6
: trimiteti comanda de QUIT
// TODO
9
: inchideti socket-ul TCP client
// TODO
7
: inchideti socket-ul TCP client
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment