Skip to content

Commit

Permalink
Merge pull request #7 from doronz88/bugfix/close
Browse files Browse the repository at this point in the history
fix handle closing
  • Loading branch information
doronz88 committed Apr 11, 2024
2 parents 77b5124 + 6748a95 commit c3a5ea2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions darwin_pytun.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ static PyObject *pytun_tuntap_down(PyObject *self) {
memset(&req, 0, sizeof(req));
strcpy(req.ifr_name, tuntap->name);
if (ioctl(tuntap->fd, SIOCGIFFLAGS, &req) < 0) {
raise_error_from_errno();
return NULL;
}
if (req.ifr_flags & IFF_UP) {
req.ifr_flags &= ~IFF_UP;
if (ioctl(tuntap->fd, SIOCSIFFLAGS, &req) < 0) {
raise_error_from_errno();
return NULL;
}
}
Expand Down
8 changes: 6 additions & 2 deletions pytun_pmd3/wintun.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ def interface_index(self) -> int:
return self.ip_interface_entry.InterfaceIndex

def close(self) -> None:
wintun.WintunCloseAdapter(self.handle)
self.down()
if self.handle is not None:
wintun.WintunCloseAdapter(self.handle)
self.handle = None

@property
def addr(self) -> str:
Expand All @@ -270,7 +273,8 @@ def up(self, capacity: int = DEFAULT_RING_CAPCITY) -> None:
self.session = wintun.WintunStartSession(self.handle, capacity)

def down(self) -> None:
wintun.WintunEndSession(self.session)
if self.session is not None:
wintun.WintunEndSession(self.session)
self.session = None

def read(self) -> bytes:
Expand Down

0 comments on commit c3a5ea2

Please sign in to comment.